package com.example.dllo.my36kr.find.activities;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.tools.NetTool;

/**
 * Created by dllo on 16/8/25.
 * 近期活动的Adapter
 */
public class NearAdapter extends BaseAdapter {
    Context mContext;
    NearBean nearBean;
    private final NetTool mNetTool;

    public void setNearBean(NearBean nearBean) {
        this.nearBean = nearBean;
    }

    public NearAdapter(Context mContext) {
        this.mContext = mContext;
        mNetTool = new NetTool();
    }

    @Override
    public int getCount() {
        return nearBean.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NearHolder holder =null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_nearterm_item,null);
            holder = new NearHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (NearHolder) convertView.getTag();
        }
        mNetTool.getImage(nearBean.getData().getData().get(position).getActivityImg(),holder.activityImgIv);
        holder.activityTimeTv.setText(nearBean.getData().getData().get(position).getActivityTime());
        holder.activityCityTv.setText(nearBean.getData().getData().get(position).getActivityCity());
        holder.activityDescTv.setText(nearBean.getData().getData().get(position).getActivityDesc());
        holder.activityNameTv.setText(nearBean.getData().getData().get(position).getActivityName());
        holder.activityStatusTv.setText(nearBean.getData().getData().get(position).getActivityStatus());

        return convertView;
    }
    public class NearHolder{
        ImageView activityImgIv;
        TextView activityCityTv,activityDescTv,activityNameTv,activityStatusTv,activityTimeTv;

        public NearHolder(View view) {
            activityImgIv = (ImageView) view.findViewById(R.id.iv_nearterm_activityImg);
            activityCityTv = (TextView) view.findViewById(R.id.tv_nearterm_activityCity);
            activityDescTv = (TextView) view.findViewById(R.id.tv_nearterm_activityDesc);
            activityNameTv = (TextView) view.findViewById(R.id.tv_nearterm_activityName);
            activityStatusTv = (TextView) view.findViewById(R.id.tv_nearterm_activityStatus);
            activityTimeTv = (TextView) view.findViewById(R.id.tv_nearterm_activityTime);
        }
    }
}
